package com.datastructure.test.rotatearray;

public class RotateArray {

    public static void main(String[] args) {
        RotateArray rotateArray = new RotateArray();
        int[] data = {1,2,3,4,5,6};
        rotateArray.solve(6,2,data);
    }

    public int[][] rotateMatrix(int[][] mat, int n) {
        // write code here
        int[][] result = new int[n][n];
        for (int i = 0; i < result.length; i++) {
            for (int j = 0; j < result[0].length; j++) {
                result[i][j]=mat[n-j-1][i];
            }
        }
        return result;
    }

    public int[] solve (int n, int m, int[] a) {
        // write code here
        if(m==0){
            return a;
        }
        if(m>n){
            m=m%n;
        }
        int k = n-m;
        for(int i = n-m;i<n;i++){
            int f = i;
            for (int j = 0; j < k; j++,f--) {
                swap(a,f,f-1);
            }
        }
        return a;
    }

    public void swap(int[] array,int left,int right){
        int temp = array[left];
        array[left]=array[right];
        array[right]=temp;
    }

}
